﻿using System;
using System.Collections.Generic;
using System.Text;
using Antu.WebControls;
using System.Web;
using EluZSProvider;
using System.Web.UI.WebControls;
using Antu.Core.Services;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class eTreeControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (base.Page.Session["UserID"] != null)
            {
                userid = base.Page.Session["UserID"].ToString();
            }
            else
            {
                Antu.Utilities.UtilitiesPage.RegJsScript("window.parent.location.href('login.aspx');");
            }
            base.OnLoad(e);
            MPRepeater bMPRepeater = (MPRepeater)FindControl("bMPRepeater");
            bMPRepeater.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(bMPRepeater_ItemDataBound);
            if (!_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid))
            {
                DataTable dt = _EluZSDataProvider.GetMenuTitleByUserID(userid);
                bMPRepeater.DataSource = dt;
                bMPRepeater.DataBind();
            }
            else
            {
                List<EluZSProvider.Menu> menu = _EluZSDataProvider.GetMenuTitle();
                bMPRepeater.DataSource = menu;
                bMPRepeater.DataBind();
            }
        }
        protected void bMPRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (!_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid))
            {
                DataRowView dr = (DataRowView)e.Item.DataItem;
                Literal showbmenu = (Literal)e.Item.FindControl("showbmenu");
                int itemindex = (e.Item.ItemIndex + 1);
                MPRepeater sMPRepeater = (MPRepeater)e.Item.FindControl("sMPRepeater");
                sMPRepeater.ItemDataBound += new RepeaterItemEventHandler(sMPRepeater_ItemDataBound);
                DataTable dt = _EluZSDataProvider.GetMenuByUserID(userid, dr["ID"].ToString());
                sMPRepeater.DataSource = dt;
                sMPRepeater.DataBind();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "show1", "<script>show1('" + dr["Order_id"].ToString() + "');</script>");
            }
            else {
                EluZSProvider.Menu dr = (EluZSProvider.Menu)e.Item.DataItem;
                Literal showbmenu = (Literal)e.Item.FindControl("showbmenu");
                int itemindex = (e.Item.ItemIndex + 1);
                MPRepeater sMPRepeater = (MPRepeater)e.Item.FindControl("sMPRepeater");
                sMPRepeater.ItemDataBound += new RepeaterItemEventHandler(sMPRepeater_ItemDataBound);
                List<EluZSProvider.Menu> menucon = _EluZSDataProvider.GetMenu(dr.Id);
                sMPRepeater.DataSource = menucon;
                sMPRepeater.DataBind();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "show1", "<script>show1('" + dr.Order_id + "');</script>");
            }
            
        }

        protected void sMPRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (!_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid))
            {
                Literal showsmenu = (Literal)e.Item.FindControl("showsmenu");
                int itemindex = (e.Item.ItemIndex + 1);
                Literal showid = (Literal)e.Item.FindControl("showid");
                MPRepeater ssMPRepeater = (MPRepeater)e.Item.FindControl("ssMPRepeater");
                DataTable dt = _EluZSDataProvider.GetMenuContentByUserID(userid, showid.Text);
                ssMPRepeater.DataSource = dt;
                ssMPRepeater.DataBind();
            }
            else {
                Literal showsmenu = (Literal)e.Item.FindControl("showsmenu");
                int itemindex = (e.Item.ItemIndex + 1);
                Literal showid = (Literal)e.Item.FindControl("showid");
                MPRepeater ssMPRepeater = (MPRepeater)e.Item.FindControl("ssMPRepeater");
                List<EluZSProvider.Menu> menucon = _EluZSDataProvider.GetMenuContent(showid.Text);
                ssMPRepeater.DataSource = menucon;
                ssMPRepeater.DataBind();
            }
            
        }
    }
}
